package com.aegean.MonitorExamSYS.examinee.action;

import java.io.InputStream;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.examinee.business.ExamineeBusiness;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;
@Controller("UserLoginAction")
@Scope("prototype")
public class UserLoginAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -8869800796212844860L;
	@Resource
	ExamineeBusiness business;
    private String user_Login;
    private String user_Password;
    private InputStream user_Photo;
	public InputStream getUser_Photo() {
		return user_Photo;
	}

	public void setUser_Photo(InputStream user_Photo) {
		this.user_Photo = user_Photo;
	}

	public String getUser_Login() {
		return user_Login;
	}

	public void setUser_Login(String user_Login) {
		this.user_Login = user_Login;
	}

	public String getUser_Password() {
		return user_Password;
	}

	public void setUser_Password(String user_Password) {
		this.user_Password = user_Password;
	}
    
	@Override
	public void validate() {
		// TODO Auto-generated method stub
		if(user_Login==null||user_Login.length()==0||user_Password==null||user_Password.length()==0){
			this.addFieldError("user_Login","对不起，用户名或者密码不能为空！");
		}
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		ExamineeValue user=business.loginUser(user_Login, user_Password);
        if(user==null){
        	return LOGIN;
        }
        else{
        	ServletActionContext.getRequest().getSession().setAttribute("UserLogin",user);
        	return SUCCESS;
        }
	}

}
